package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Text;
	/**
	 * © 2012 TheJavaArcade.com
	 */
	public class Heart extends Entity {
		private var heartSprite:Image = new Image(Assets.HEART_SPRITE);
		public var level:int;
		public var state:int;
		public var theText:Text = new Text("");;
		public var count:int;
		
		public function Heart(theLevel:int) {
			level = theLevel;
			type = "heart";
			setHitbox(16, 16, 0, 0);
			layer = 1;
			state = 0;
			graphic = heartSprite;
			theText.text = "    Speed +1    \n   Strength +1  \nRegeneration + 1";
			theText.size = 8;
			visible = false;
			var dataList:XMLList;
			var dataElement:XML;
			dataList = GameEngine.levelXML[theLevel].items.heart;
			for each(dataElement in dataList) {
				x = dataElement.@x;
				y = dataElement.@y;
			}
		}
		override public function update():void {
			if (GameEngine.level == level && state == 1) {
				if (collide("fracas", x, y)) {
					GameEngine.score += 10000;
					state = 2;
					GameEngine.fracas.speed++;
					GameEngine.fracas.strength++;
					GameEngine.fracas.regeneration++;
					graphic = theText;
					count = 40;
					y = y - 25;
				}
			}
			if (state == 2) {
				count--;
				x = GameEngine.fracas.x- 20;
				y = y - 1;
				if(count==0)FP.world.remove(this);
			}
		}
	}

}